// 119. 杨辉三角 II
class Solution {
public:
    vector<int> getRow(int rowIndex) {
        vector<int>  ret(rowIndex + 1);
        ret[0] = 1;
        for(int m = 1; m <= rowIndex; m++)
        {
            ret[m] = (long long)ret[m-1] * (rowIndex-m+1) / m;
        }
        return ret;
    }
}; 

// 1658. 将 x 减到 0 的最小操作数
class Solution {
public:
    int sum(vector<int>& nums)
    {
        int ret = 0;
        for(auto e : nums)
            ret += e;
        return ret;
    }

    int minOperations(vector<int>& nums, int x) {
        int target = sum(nums) - x, sum = 0, len = -1;
        if(target < 0) return -1;

        for(int left = 0, right = 0; right < nums.size(); right++)
        {
            sum += nums[right];
            while(sum > target) sum -= nums[left++];
            if(sum == target) len = max(len, right - left + 1);
        }
        if(len == -1) return -1;
        else return nums.size() - len;
    }
};